# -*- coding: utf-8 -*-
import sys

sys.path.append('../')

from chemdb import dbHandle
dbHandle.reconnect('chemdb_user', 'origindb')

#Data:
compound1 = {'name'		:"adenine",
			 'formula'	:"C5H5N5",
			 'iupac'	:"7H-purin-6-amine",
			 'inchi'	:"1/C5H5N5/c6-4-3-5(9-1-7-3)10-2-8-4/h1-2H,(H3,6,7,8,9,10)/f/h7H,6H2",
			 'molfile'	:"THIS IS A TEST MOLEFILE    ",
			 'fp'		:"213  zaf34   34 "
			 }
compound2 = {'name'		:"formic acid",
			 'formula'	:"CH5NO2",
			 'iupac'	:"azanium formate",
			 'inchi'	:"THIS IS A TEST INCHI",
			 'molfile'	:"THIS IS A TEST MOLEFILE2    ",
			 'fp'		:"1561 3584 TEST TEST ase 654  "
			 }
compound3 = {'name'		:"Sulfur",
			 'formula'	:"S",
			 'iupac'	:"sulfur",
			 'inchi'	:"THIS IasdfS A TEST INCHI",
			 'molfile'	:"THIS IS A asdfTEST MOLEFILE3    ",
			 'fp'		:"1561 3584 TESasdfT TEST ase 654  "
			 }
reference1 = {'name'	:"SYNTHESIS OF ADENINE FROM HCN TETRAMER AND AMMONIUM FORMATE",
			  'author' 	:"LESLIE E. ORGEL",
			  'year'	:"2002",
			  'source'	:"Nature"
			  }
reaction1 = {'references':[reference1['name']],
			 'temp'		:110,
			 'solvent'	:'water',
			 'state'	:'liquid',
			 'pressure'	:1.0,
			 'time'		:3,
			 'pH'		:7.4,
			 'other'	:"Other",
			 'catalysts':["quartz"]
			 }
catalyst1 = {'name'	:"quartz"}
catalyst2 = {'name'	:"dirt"}

def populateDB():
	clearDB()
	dbHandle.reconnect('chemdb_user', 'origindb')
	dbHandle.insertUser('jason', '', '', '')
	dbHandle.uid = 1

	compound1Id = dbHandle.insertCompound(compound1['name'], compound1['formula'], compound1['iupac'])
	compound2Id = dbHandle.insertCompound(compound2['name'], compound2['formula'], compound2['iupac'])
	compound3Id = dbHandle.insertCompound(compound3['name'], compound3['formula'], compound3['iupac'])
	dbHandle.insertInchi(compound1Id, compound1['inchi'])
	dbHandle.insertMol(compound1Id, compound1['molfile'])
	dbHandle.insertFingerprint(compound1['fp'], compound1Id)
	dbHandle.insertInchi(compound2Id, compound2['inchi'])
	dbHandle.insertMol(compound2Id, compound2['molfile'])
	dbHandle.insertFingerprint(compound2['fp'], compound2Id)
	dbHandle.insertInchi(compound3Id, compound3['inchi'])
	dbHandle.insertMol(compound3Id, compound3['molfile'])
	dbHandle.insertFingerprint(compound3['fp'], compound3Id)
	reference1Id = dbHandle.insertReference(reference1['name'], reference1['author'], reference1['year'], reference1['source'])
	reaction1Id = dbHandle.insertReaction(reference1Id, reaction1['temp'], reaction1['solvent'], reaction1['state'], reaction1['pressure'], reaction1['time'], reaction1['pH'], reaction1['other'])
	catalyst1Id = dbHandle.insertCatalyst(catalyst1['name'], reaction1Id)
	catalyst2Id = dbHandle.insertCatalyst(catalyst2['name'], reaction1Id)
	relation1Id = dbHandle.insertRelation(compound2Id, compound1Id, reaction1Id)
	relation2Id = dbHandle.insertRelation(compound3Id, compound1Id, reaction1Id)

def clearDB():
	from os import system
	system("mysql -u testing < ../chemdb.sql") # This clears the database